﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using ThreeThingGame;

namespace ProtectThePie
{
    public class GameplayBackground
    {
        private Point fieldSize;
        private Rectangle rectangle;
        private Rectangle sourceRectangle;
        private Vector2 origin;
        private Texture2D texture;

        /// <summary>
        /// will change current texture
        /// </summary>
        /// <param name="newTexture"></param>
        public void ChangeTexture(Texture2D newTexture)
        {
            this.texture = newTexture;
        }

        /// <summary>
        /// Constructor of Gameplay Background
        /// </summary>
        /// <param name="fieldSize">size of the field where to draw background</param>
        public GameplayBackground(Point fieldSize) 
        {
            this.fieldSize = fieldSize;
            //this.texture = Game1.backgroundTextures[0];
            this.rectangle = new Rectangle(fieldSize.X / 2, fieldSize.Y / 2, fieldSize.X, fieldSize.Y);
            this.sourceRectangle = new Rectangle(0, 0, fieldSize.X, fieldSize.Y);
            this.origin = new Vector2(fieldSize.X / 2, fieldSize.Y / 2);
        }

        /// <summary>
        /// Constructor of Gameplay Background
        /// </summary>
        /// <param name="fieldSize">size of the field where to draw background</param>
        /// <param name="texture">first texture name</param>
        public GameplayBackground(Point fieldSize, Texture2D texture)
        {
            this.fieldSize = fieldSize;
            this.texture = texture;
            this.rectangle = new Rectangle(fieldSize.X / 2, fieldSize.Y / 2, fieldSize.X, fieldSize.Y);
            this.sourceRectangle = new Rectangle(0, 0, fieldSize.X, fieldSize.Y);
            this.origin = new Vector2(fieldSize.X / 2, fieldSize.Y / 2);
        }

        /// <summary>
        /// Draws Gameplay Background
        /// </summary>
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, rectangle, sourceRectangle, Color.White, 0, origin, SpriteEffects.None, 0);
        }
    }
}
